package com.qs;

import javax.servlet.ServletConfig;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class FirstServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        System.out.println("firstServlet");
        response.setContentType("text/html");
        PrintWriter pw = response.getWriter();
        pw.write("<h1>hello first servlet</h1>");
//        ServletConfig config = getServletConfig();
//        String driver = config.getInitParameter("driver");
//        String url = config.getInitParameter("url");
//        String user = config.getInitParameter("user");
//        String pass = config.getInitParameter("pass");
//        try{
//            Class.forName(driver);
//            Connection conn = DriverManager.getConnection(url);
//            Statement stmt = conn.createStatement();
//            ResultSet rs = stmt.executeQuery("select * from user");
//            PrintStream out = new PrintStream(response.getOutputStream());
//            out.print("<table>");
//            while (rs.next())
//            {
//                out.print("<tr>");
//                out.print("<td>"+rs.getString("username")+"</td>");
//                out.print("<td>"+rs.getString("email")+"</td>");
//                out.print("</tr>");
//            }
//            out.print("</table>");
//        }catch (Exception e)
//        {
//
//        }

    }
}
